//
//  LoginVC.swift
//  Drop
//
//  Created by zhuxuhong on 2018/3/16.
//  Copyright © 2018年 zhuxuhong. All rights reserved.
//

import UIKit

class LoginVC: UIViewController {

    @IBOutlet weak var logoIV: UIImageView!
    @IBOutlet weak var tipsLabel: UILabel!
    @IBOutlet weak var wetchatBtn: UIButton!
    @IBOutlet weak var logoIVTopConstraint: NSLayoutConstraint!

    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        wetchatBtn.alpha = 0
        logoIVTopConstraint.constant = -64
        tipsLabel.alpha = 0
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        startAnimation()
    }
    
    func startAnimation() {
        logoIVTopConstraint.constant = wetchatBtn.frame.origin.y
        UIView.animate(withDuration: 1.5,
                       delay: 0.5,
                       usingSpringWithDamping: 1,
                       initialSpringVelocity: 0,
                       options: .curveEaseOut,
                       animations:
            {
                self.view.layoutIfNeeded()
        }, completion: { _ in
            self.alphaAnimation(alpha: 0, for: self.logoIV, completion: {
                self.logoIVTopConstraint.constant = 200
                self.alphaAnimation(alpha: 1, for: self.wetchatBtn, completion: {
                    self.alphaAnimation(alpha: 1, for: self.logoIV, completion: {
                        self.alphaAnimation(alpha: 1, for: self.tipsLabel, completion: nil)
                    })
                })
            })
        })
    }
    
    func alphaAnimation(alpha: CGFloat, for view: UIView, completion: (()->Void)?) {
        UIView.animate(withDuration: 0.8, animations: {
            view.alpha = alpha
        }, completion: { _ in
            completion?()
        })
    }
}
